package com.wanmait.recruitment.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.recruitment.mapper.DeliverMapper;
import com.wanmait.recruitment.pojo.Deliver;
import com.wanmait.recruitment.pojo.Job;
import com.wanmait.recruitment.service.DeliverService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class DeliverServiceImpl implements DeliverService

{
    @Resource
    private DeliverMapper deliverMapper;


    @Override
   // @CacheEvict(value = "deliverCache",allEntries = true)
    public void insert(Deliver object) {
        deliverMapper.insert(object);
    }

    @Override
    //@CacheEvict(value = "deliverCache",allEntries = true)
    public void delete(Integer id) {
        deliverMapper.deleteById(id);
    }


    @Override
    //@Cacheable("deliverCache")
    public PageInfo<Deliver> findPage(int pageNum, int pageSize, Integer companyId, Integer exRequireId, Integer degreeId, Integer state) {
        PageHelper.startPage(pageNum,pageSize);
        List<Deliver>delivers = deliverMapper.findBycompany(companyId,exRequireId,degreeId,state);
        List<Deliver>delivers1 = new ArrayList<>();
        //根据职位要求自动过滤
        for (Deliver deliver :delivers)
        {
           /* if (deliver.getResume().getExRequire().getId()==null&&deliver.getJob().getExRequire().getId()==null&&deliver.getJob().getDegree().getId()==null&&deliver.getResume().getEducation().getDegree().getId()==null)
            {
                delivers.remove(deliver);
            }
            else {*/
                if (deliver.getResume().getExRequire().getId() >= deliver.getJob().getExRequire().getId() || deliver.getJob().getDegree().getId() <= deliver.getResume().getEducation().getDegree().getId()) {
                    delivers1.add(deliver);
                }
           /* }*/
        }
        PageInfo<Deliver>pageInfo = new PageInfo<>(delivers1);

        return pageInfo;
    }

    @Override
    //@Cacheable("deliverCache")
    public List<Deliver> findBycompanyId(Integer id) {

        return deliverMapper.findBycompanyId(id);
    }

    @Override
    public int inappropriate(Integer id) {
        return deliverMapper.inappropriate(id);
    }

    @Override
   // @Cacheable("deliverCache")
    public PageInfo<Deliver> inappropriateList(Integer id,int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Deliver>delivers = deliverMapper.inappropriateList(id);

        PageInfo<Deliver>pageInfo = new PageInfo<>(delivers);
        return pageInfo;
    }

    @Override
   // @CacheEvict(value = "deliverCache",allEntries = true)
    public int removed(Integer id) {
      return deliverMapper.removed(id);
    }

    @Override
    public int findByJobResume(Integer id) {
        return deliverMapper.findByJobResume(id);
    }

    @Override
    public int canInterview(Integer id) {
        return deliverMapper.canInterview(id);
    }

    @Override
    public int adopt(Integer id) {
        return deliverMapper.adopt(id);
    }

    @Override
    //@Cacheable("deliverCache")
    public PageInfo<Deliver> canInterviewResumes(int pageNum, int pageSize,Integer companyId, Integer exRequireId, Integer degreeId, Integer state) {
        PageHelper.startPage(pageNum,pageSize);
        List<Deliver>delivers = deliverMapper.canInterviewResumes(companyId,exRequireId,degreeId,state);

        PageInfo<Deliver>pageInfo = new PageInfo<>(delivers);
        return pageInfo;
    }


    @Override
    //@Cacheable("deliverCache")
    public PageInfo<Deliver> haveNoticeResumes(Integer id,int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Deliver>delivers = deliverMapper.haveNoticeResumes(id);

        PageInfo<Deliver>pageInfo = new PageInfo<>(delivers);
        return pageInfo;
    }

    @Override
    //@Cacheable("deliverCache")
    public PageInfo<Deliver> pending(int pageNum, int pageSize,Integer companyId, Integer exRequireId,Integer degreeId,Integer state) {
        PageHelper.startPage(pageNum,pageSize);
        List<Deliver>delivers = deliverMapper.pending(companyId,exRequireId,degreeId,state);
        PageInfo<Deliver>pageInfo = new PageInfo<>(delivers);
        return pageInfo;
    }

    @Override
   // @Cacheable("deliverCache")
    public PageInfo<Deliver> findByUserId(int pageNum, int pageSize,Integer id,Integer state) {
        PageHelper.startPage(pageNum,pageSize);
        List<Deliver>delivers = deliverMapper.findByUserId(id, state);
        PageInfo<Deliver>pageInfo = new PageInfo<>(delivers);

        return pageInfo;
    }

    @Override
    public int Viewed(Integer id) {
        return deliverMapper.Viewed(id);
    }

    @Override
    public int updateResumeState(Integer deliverId,Integer resumeStateId) {
        return deliverMapper.updateResumeState(deliverId,resumeStateId);
    }

    @Override
    public Deliver selectById(Integer id) {
        return deliverMapper.selectById(id);
    }


    @Override
    public void delete(String ids) {
    }

    @Override
    public void update(Deliver object) {

    }
    @Override
    public Deliver findById(Integer id) {
        return null;
    }

    @Override
    public List<Deliver> findAll() {
        return null;
    }

    @Override
    public List<Deliver> findAll(Deliver object) {
        return null;
    }

    @Override
    public Deliver selectByUserinfoId(Integer userinfoId, Integer jobId) {
        return deliverMapper.selectByUserinfoId(userinfoId,jobId);
    }

    @Override
    public List<Job> findBycompany(Integer companyId) {
        return null;
    }

    @Override
    public PageInfo findPage(int pageNum, int pageSize) {
        return null;
    }
}
